package cn.com.surker.material.controller;

import cn.com.surker.common.AbstractController;
import cn.com.surker.dto.main.MainDiscountQueryDTO;
import cn.com.surker.dto.main.MainDiscountUpdateDTO;
import cn.com.surker.material.service.MainMaterialDiscountService;
import cn.com.surker.spring.RestResultDto;
import cn.com.surker.system.model.CacheUser;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mainmaterialdiscount")
public class MainMaterialDiscountController extends AbstractController {


    @Resource
    private MainMaterialDiscountService mainMaterialDiscountService;


    /**
     * 材料扣重设置 分页方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/page")
    public RestResultDto pageData(@RequestBody MainDiscountQueryDTO dto){
        return RestResultDto.success(mainMaterialDiscountService.pageData(dto));
    }

    /**
     * 材料扣重设置新增方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/save")
    public RestResultDto save(@RequestBody MainDiscountUpdateDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(mainMaterialDiscountService.saveMainMaterialDiscount(dto,user));
    }

    /**
     * 材料扣重设置更新方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/update")
    public RestResultDto update(@RequestBody MainDiscountUpdateDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(mainMaterialDiscountService.updateMainMaterialDiscount(dto,user));
    }

    /**
     * 材料扣重设置更新方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/updatestatus")
    public RestResultDto updatestatus(@RequestBody MainDiscountUpdateDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(mainMaterialDiscountService.updateStatusById(dto,user));
    }

    /**
     * 获取单位关联的材料类型信息
     * @param orgId
     * @return
     */
    @PostMapping(value = "/getMaterialList")
    public RestResultDto getMaterialListByOrgId(String orgId, Long supplierId){
        List<Map<String, Object>> materialListByOrgId = mainMaterialDiscountService.getMaterialListByOrgId(orgId, supplierId);
        return RestResultDto.success(materialListByOrgId);
    }

    /**
     * 获取单位关联的供应商信息
     * @param orgId
     * @return
     */
    @PostMapping(value = "/getSupplierList")
    public RestResultDto getSupplierListByOrgId(String orgId){
        List<Map<String, Object>> supplierListByOrgId = mainMaterialDiscountService.getSupplierListByOrgId(orgId);
        return RestResultDto.success(supplierListByOrgId);
    }



}
